package pl.edu.agh.gp.stock;

import org.jgap.InvalidConfigurationException;
import org.jgap.gp.CommandGene;
import org.jgap.gp.function.And;
import org.jgap.gp.impl.GPConfiguration;
import org.jgap.gp.impl.GPGenotype;
import org.jgap.gp.terminal.Terminal;
import org.jgap.gp.terminal.True;
import org.jgap.gp.terminal.Variable;
import pl.edu.agh.gp.common.GenotypeProvider;
import pl.edu.agh.gp.nodes.math.Mean;
import pl.edu.agh.gp.nodes.math.StandardDeviation;
import pl.edu.agh.gp.nodes.math.ExpMovAvg;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import static org.jgap.gp.CommandGene.DoubleClass;

public class StockGenotypeProvider extends GenotypeProvider {
    public GPGenotype getEMAGenotype(GPConfiguration conf, int maxNodes) throws InvalidConfigurationException {
        Random random = new Random();
        int maxArity = 100;

        CommandGene[] partialNodeSet = {
                openPrice = Variable.create(conf, "OpenPrice", DoubleClass),
                highPrice = Variable.create(conf, "HighPrice", DoubleClass),
                lowPrice = Variable.create(conf, "LowPrice", DoubleClass),
                closePrice = Variable.create(conf, "ClosePrice", DoubleClass),
                volume = Variable.create(conf, "Volume", DoubleClass),
                prices = Variable.create(conf, "Prices", List.class),

                new And(conf),
                new True(conf),
                new StandardDeviation(conf, random.nextInt(maxArity - 2) + 2, maxArity, DoubleClass),
                new StandardDeviation(conf, random.nextInt(maxArity - 2) + 2, maxArity, List.class),
                new Mean(conf, random.nextInt(maxArity - 2) + 2, maxArity, DoubleClass),
                new Mean(conf, random.nextInt(maxArity - 2) + 2, maxArity, List.class),
                new ExpMovAvg(conf, random.nextInt(maxArity - 2) + 2, maxArity, DoubleClass),
                new ExpMovAvg(conf, random.nextInt(maxArity - 2) + 2, maxArity, List.class),
        };

        List<CommandGene> partialNodesWithTerminals = new LinkedList<CommandGene>();
        for(CommandGene gene: partialNodeSet){
            partialNodesWithTerminals.add(gene);
        }
        int terminalsSize = 100;
        for(int i = 0; i < terminalsSize; i++){
            partialNodesWithTerminals.add(new Terminal(conf, DoubleClass, 0.0, 1000.0, false));
        }

        return getGenotype(partialNodesWithTerminals.toArray(new CommandGene[]{}),conf,maxNodes);
    }
}